PROGRAM matrix
IMPLICIT NONE

INTEGER, DIMENSION(2,2) :: a,b,c
INTEGER :: i
OPEN(1,FILE='input_q4.dat')
DO i=1,2
  READ (1,*),a(i,1), a(i,2)
END DO

DO i=1,2
  READ (1,*),b(i,1), b(i,2)
END DO
CLOSE(1)
OPEN(2,FILE='output_q4.dat',STATUS='UNKNOWN')
c=a+b
WRITE(2,*),'A+B'
WRITE(2,'(I2 I2/I2 I2/)'),c(1,1),c(1,2),c(2,1),c(2,2)
c=a-b
WRITE(2,*),'A-B'
WRITE(2,'(I2 I2/I2 I2/)'),c(1,1),c(1,2),c(2,1),c(2,2)
c=TRANSPOSE(a)
WRITE(2,*),'A transpose'
WRITE(2,'(I2 I2/I2 I2/)'),c(1,1),c(1,2),c(2,1),c(2,2)
c=MATMUL(a, b)
WRITE(2,*),'AB'
WRITE(2,'(I2 I2/I2 I2/)'),c(1,1),c(1,2),c(2,1),c(2,2)
c=MATMUL(b, a)
WRITE(2,*),'BA'
WRITE(2,'(I2 I2/I2 I2/)'),c(1,1),c(1,2),c(2,1),c(2,2)
END PROGRAM
